<?php

if (!pdo_fetch('DESCRIBE sh_banner `image_width`')) {
    pdo_query("ALTER TABLE sh_banner ADD image_width INT(4) NOT NULL DEFAULT 0 AFTER `name`;" );
    pdo_query("ALTER TABLE sh_banner ADD image_height INT(4) NOT NULL DEFAULT 0 AFTER `name`;" );
}


pdo_fetch( "ALTER TABLE sh_order_total CHANGE `value` `value` DECIMAL(10,2) NOT NULL;");
pdo_fetch( "ALTER TABLE sh_order_goods CHANGE `goods_price` `goods_price` DECIMAL(10,2) NOT NULL;");
pdo_fetch( "ALTER TABLE sh_order_goods CHANGE `goods_total` `goods_total` DECIMAL(10,2) NOT NULL;");


if (!pdo_fetch('DESCRIBE sh_goods `sale`')) {
    pdo_query("ALTER TABLE sh_goods ADD sale INT(10) NOT NULL DEFAULT 0 COMMENT '商品销量，用来展示在前台'  AFTER price;" );
}
if (!pdo_fetch('DESCRIBE sh_goods `model`')) {
    pdo_query("ALTER TABLE sh_goods ADD model VARCHAR(64) NOT NULL DEFAULT '' COMMENT '商品型号' AFTER price;" );
}

if (!pdo_fetch('DESCRIBE sh_goods `special`')) {
    pdo_query("ALTER TABLE sh_goods ADD `special` DECIMAL (10, 2) NOT NULL DEFAULT 0 COMMENT '商品特殊价格' AFTER `price`;" );
}

if( !pdo_exists('sh_goods_comment' ) ){

    pdo_query("
        CREATE TABLE `sh_goods_comment` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `goods_id` int(11) NOT NULL,
  `customer_id` int(11) NOT NULL DEFAULT '0',
  `author` varchar(255) NOT NULL,
  `date` datetime NOT NULL COMMENT '评论时间，显示给客户',
  `content` text,
  `score` int(1) NOT NULL DEFAULT '5' COMMENT '1-5分',
  `images` text,
  `status` int(1) NOT NULL DEFAULT '1',
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `goods_id` (`goods_id`),
  KEY `customer_id` (`customer_id`),
  KEY `author` (`author`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    ");
}

if (!pdo_fetch('DESCRIBE sh_customer `info`')) {
    pdo_query("ALTER TABLE sh_customer ADD `info` TEXT NULL AFTER `status`;" );
}

if (!pdo_fetch('DESCRIBE sh_customer `remark`')) {
    pdo_query("ALTER TABLE sh_customer ADD `remark` TEXT NOT NULL AFTER `status`;" );
}

if (!pdo_fetch('DESCRIBE sh_customer `uniacid`')) {
    pdo_query("ALTER TABLE sh_customer ADD uniacid INT(10) UNSIGNED NOT NULL AFTER id ;");
}

if( !pdo_exists('sh_brand' ) ){
    pdo_query(
        "CREATE TABLE `sh_brand` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(64) NOT NULL,
  `img` varchar(255) NOT NULL,
  `letter_pre` varchar(1) NOT NULL,
  `status` int(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
    );
}

if (!pdo_fetch('DESCRIBE sh_goods `brand_id`')) {
    pdo_query("ALTER TABLE sh_goods ADD `brand_id` INT (11) NOT NULL DEFAULT 0 AFTER `name` ;");
}

if (!pdo_fetch('DESCRIBE sh_goods_comment `avatar`')) {
    pdo_query("ALTER TABLE sh_goods_comment ADD `avatar` VARCHAR(255) NOT NULL AFTER `author`;");
}

pdo_run( '
ALTER TABLE sh_customer DROP INDEX telephone;
ALTER TABLE sh_customer ADD INDEX `telephone` (`telephone`);
' );

if (!pdo_fetch('DESCRIBE sh_order `apply_refund`')) {
    pdo_query("ALTER TABLE sh_order ADD `apply_refund` INT(1) NOT NULL DEFAULT 0 COMMENT '用户申请退款' AFTER `is_payed`;");
}

if (!pdo_fetch('DESCRIBE sh_goods `sale_add`')) {
    pdo_query("ALTER TABLE sh_goods ADD sale_add TINYINT NOT NULL DEFAULT 0 COMMENT '商品每日虚拟增长数量范围：0-值' AFTER `sale`;");
}